<form  action='index.php?app=inman&ctl=admin_stores&act=toAdd' method="post"  id='newstore-edit-form' class="tableform">
<div class="division">
	<!-- 店铺的信息 -->
        <table width="100%" >
            <tr><th><em class="red">*</em><{t}>店铺名称：<{/t}></th><td><{input type="text" name="store[store_name]"  onchange="nameCheck(this)" size="20" vtype="required"}><span></span></td></tr>
            <tr><th><em class="red">*</em><{t}>是否启用：<{/t}></th><td><input type="radio" name="store[status]" value='0' checked='checked'/>禁用<input type="radio" value='1' name='store[status]'/>启用</td></tr>
            <!-- <tr><th>佣金模式：</th><td>
            	<select name='store[store_type]'>
            		<option value='0'>默认</option>
            		<option value='1'>线上佣金规则</option>
            		<option value='2'>官网佣金规则</option>
            		<option value='3'>非官网佣金规则</option>
            	</select>
            <span></span></td></tr> -->
            <tr><th>绑定码：</th><td><{input type="text" name="store[store_bn]" value=$storeBn  readonly='readonly' size="20"}><span>&nbsp;&nbsp;&nbsp;<input type='button' value='随机生成'/></span></td></tr>
           	 </tr> 
           	 <tr>
	            <th><em class="red">*</em><{t}>挂板数目：<{/t}></th>
	            <td>
					<{input type="text" name="store[panel_num]"  size="20" vtype="required"}>	            	<span id='info-name'></span>
	            </td>
           	</tr> 
            <tr><th>店铺所在省市县：</th><td><{input type="region" name="store[store_area]" size="20" }><span></span></td></tr>
            <tr><th>店铺详细地址：</th><td><{input type="text" name="store[store_addr]" size="20" }><span></span></td></tr>
            <tr><th>店铺简介：</th><td><textarea cols='40' rows='5' name="store[store_desc]"></textarea><span></span></td></tr>
            <tr><th>店铺经度：</th><td><{input type="text" name="store[store_x]" size="20" }><span></span></td>
            	<th>店铺纬度：</th><td><{input type="text" name="store[store_y]" size="20" }><span></span></td>
            </tr>
            <tr><th>店铺图片：</th><td><{input type="image" name="store[store_image_id]" size="20" }><span></span></td></tr>
        </table>
       
	</div>
	<!-- 绑定的分销商信息 -->
	<div class="division">
		 <table  width="100%">
		 <tr><th><em class="red">*</em><{t}>分销商登录名：<{/t}></th>
	            <td>
					<{input type="text" name="store[login_account]"  readonly='readonly'  value=$login_account  onchange="nameCheck(this)" size="20" vtype="required"}>	            	<span id='info-name'></span>
	            </td>
	     <tr>
         <tr>
	            <th><em class="red">*</em><{t}>联系人：<{/t}></th>
	            <td>
					<{input type="text" name="store[true_name]"    size="20" vtype="required"}>	            	<span id='info-name'></span>
	            </td>
	            
	            
	             <th><em class="red">*</em><{t}>联系方式：<{/t}></th>
	            <td>
					<{input type="text" name="store[phone]"  size="20" vtype="required"}>	            	<span id='info-name'></span>
	            </td>
         </tr> 
           	 <tr>
	           
	            
	            <th><em class="red">*</em><{t}>身份证：<{/t}></th>
	            <td>
					<{input type="text" name="store[id_card_number]"  onblur='isIdCardNo(this.value)' size="20" vtype="required"}>	            	<span id='info-name'></span>
	            	<span id='info-IdCard'></span>
	            </td>
	            
	            <th><em class="red">*</em><{t}>银行卡：<{/t}></th>
	            <td>
					<{input type="text" name="store[bank_card_number]"     size="20" vtype="required"}>	            	<span id='info-name'></span>
	            	<span id='info-BankCard'></span>
	            </td>
           	</tr> 
         </table>
        <hr style="margin:5px 0;">
	</div>
	<{area inject='.mainFoot'}>
		<div class="table-action"><{button type="submit"  label=$___inman="保存"|t:'inman' id='newstore-edit-form-submit'}></div>
	<{/area}>

</form>


<script type="text/javascript">
//begin
(function(){
    var _form = $('newstore-edit-form');
    var btn =$('newstore-edit-form-submit');
    var finder = finderGroup['<{$env.get.finder_id}>'];

    _form.store('target',{
        onComplete:function(){            

        },
        onSuccess:function(response){
            var hash_res_obj = JSON.decode(response);
            if (hash_res_obj.success != undefined && hash_res_obj.success != "")
            {
                try{
                    var _dialogIns = btn.getParent('.dialog').retrieve('instance');
                }catch(e){}

                if(_dialogIns)
                {
                    _dialogIns.close();
                    finder.refresh.delay(400,finder);
                }
            }
            else
            {
                //alert(hash_res_obj.error);
            }            
        }
    });

    btn.addEvent('click',function(){
        _form.fireEvent('submit',{stop:$empty});



    });

})();
//end.


//ajax验证用户名
    function checkname(input){
        new Request({
            url:'<{link app=inman ctl=admin_stores act=checkname}>',
            method:'post',
            data:input.name+'='+encodeURIComponent(input.value=input.value.trim()),
            onSuccess: function(rs) {
                rs = JSON.decode(rs);

                if(rs.error) {
                    input.getNext().innerHTML = '<span class="error caution notice-inline">' +rs.error + '</span>';
                }
                else if(rs.success) {
                    input.getNext().innerHTML = '<span class="success notice-inline">' +rs.success + '</span>';
                }
            }
        }).send();
    }

//ajax验证经纬度的正确性
function checkCoordinates(input){
	 new Request({
            url:'<{link app=inman ctl=admin_stores act=checkCoordinates}>',
            method:'post',
            data:input.name+'='+encodeURIComponent(input.value=input.value.trim()),
            onSuccess: function(rs) {
                rs = JSON.decode(rs);
                if(rs.error) {
                    input.getNext().innerHTML = '<span class="error caution notice-inline">' +rs.error + '</span>';
                }
                else if(rs.success) {
                    input.getNext().innerHTML = '<span class="success notice-inline">' +rs.success + '</span>';
                }
            }
        }).send();
}

function getRegCode(){
  //产生店铺的注册码
  alert('注册码生成...')
}
//检查身份证的格式
 function isIdCardNo(num) {           
        num = num.toUpperCase();           //身份证号码为15位或者18位，15位时全为数字，18位前17位为数字，最后一位是校验位，可能为数字或字符X。       
        if (!(/(^\d{15}$)|(^\d{17}([0-9]|X)$)/.test(num))) {    
            $msg='输入的身份证号长度不对，或者号码不符合规定';  
            $('info-IdCard').innerHTML = '<span class="error caution notice-inline">' +$msg + '</span>';
            return false;        
        } //校验位按照ISO 7064:1983.MOD 11-2的规定生成，X可以认为是数字10。
        //下面分别分析出生日期和校验位
        var len, re; len = num.length; if (len == 15) {
            re = new RegExp(/^(\d{6})(\d{2})(\d{2})(\d{2})(\d{3})$/);
            var arrSplit = num.match(re);  //检查生日日期是否正确
            var dtmBirth = new Date('19' + arrSplit[2] + '/' + arrSplit[3] + '/' + arrSplit[4]);
            var bGoodDay; bGoodDay = (dtmBirth.getYear() == Number(arrSplit[2])) && ((dtmBirth.getMonth() + 1) == Number(arrSplit[3])) && (dtmBirth.getDate() == Number(arrSplit[4]));
            if (!bGoodDay) {     
            	$msg='输入的身份证号里出生日期不对！';  
                $('info-IdCard').innerHTML = '<span class="error caution notice-inline">' +$msg + '</span>';
                return false;
            } else { //将15位身份证转成18位 //校验位按照ISO 7064:1983.MOD 11-2的规定生成，X可以认为是数字10。       
                var arrInt = new Array(7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2);        
                var arrCh = new Array('1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2');     
                var nTemp = 0, i;           
                num = num.substr(0, 6) + '19' + num.substr(6, num.length - 6);          
                for(i = 0; i < 17; i ++) {                
                    nTemp += num.substr(i, 1) * arrInt[i];       
                }
                num += arrCh[nTemp % 11];
                $('info-IdCard').innerHTML = '<span class="success  notice-inline">' +'格式正确'+ '</span>';
                return true;
            }
        }
        if (len == 18) {
            re = new RegExp(/^(\d{6})(\d{4})(\d{2})(\d{2})(\d{3})([0-9]|X)$/);
            var arrSplit = num.match(re);  //检查生日日期是否正确
            var dtmBirth = new Date(arrSplit[2] + "/" + arrSplit[3] + "/" + arrSplit[4]);
            var bGoodDay; bGoodDay = (dtmBirth.getFullYear() == Number(arrSplit[2])) && ((dtmBirth.getMonth() + 1) == Number(arrSplit[3])) && (dtmBirth.getDate() == Number(arrSplit[4]));
            if (!bGoodDay) {
            	$msg='输入的身份证号里出生日期不对！';  
                $('info-IdCard').innerHTML = '<span class="error caution notice-inline">' +$msg + '</span>';
                return false;
            }
            else { //检验18位身份证的校验码是否正确。 //校验位按照ISO 7064:1983.MOD 11-2的规定生成，X可以认为是数字10。
                var valnum;
                var arrInt = new Array(7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2);
                var arrCh = new Array('1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2');
                var nTemp = 0, i;
                for(i = 0; i < 17; i ++) {
                    nTemp += num.substr(i, 1) * arrInt[i];
                }
                valnum = arrCh[nTemp % 11];
                if (valnum != num.substr(17, 1)) {
                	$msg='18位身份证的校验码不正确！应该为：' + valnum;  
                    $('info-IdCard').innerHTML = '<span class="error caution notice-inline">' +$msg + '</span>';
                    return false;
                }
                $('info-IdCard').innerHTML = '<span class="success  notice-inline">' +'格式正确'+ '</span>';
                return true;
            }
        } return false;
    }

</script>


